package org.csu.code.api.controller;

import org.csu.code.api.common.CommonResponse;
import org.csu.code.api.entity.*;
import org.csu.code.api.service.CommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Controller
@RequestMapping("/comment/")
public class CommentController {

    @Autowired
    private CommentService commentService;

    @GetMapping("farmcomments/{id}")
    @ResponseBody
    public CommonResponse<FarmComment> selectFarmComment(@PathVariable("id") int commentId) {
        return commentService.selectFarmComment(commentId);
    }

    @GetMapping("itemcomments/{id}")
    @ResponseBody
    public CommonResponse<ItemComment> selectItemComment(@PathVariable("id") int commentId) {
        return commentService.selectItemComment(commentId);
    }

    @GetMapping("like/farmcomments/{id}")
    @ResponseBody
    public CommonResponse<String> likeFarmComment(@PathVariable("id") int commentId, HttpServletRequest request) {
        return commentService.likeFarmComment(commentId,request);
    }

    @GetMapping("like/itemcomments/{id}")
    @ResponseBody
    public CommonResponse<String> likeItemComment(@PathVariable("id") int commentId, HttpServletRequest request) {
        return commentService.likeItemComment(commentId,request);
    }

    @GetMapping("likedfarmcomments")
    @ResponseBody
    public CommonResponse<List<LikeFarmComment>> selectlikefarmComments(HttpServletRequest request) {
        return commentService.selectlikefarmComments(request);
    }

    @GetMapping("likeditemcomments")
    @ResponseBody
    public CommonResponse<List<LikeItemComment>> selectlikeItemComments(HttpServletRequest request) {
        return commentService.selectlikeItemComments(request);
    }

    @GetMapping("comments/farm/{farmid}")
    @ResponseBody
    public CommonResponse<List<FarmComment>> selectFarmCommentsByFarmId(@PathVariable("farmid") int farmId) {
        return commentService.selectFarmCommentsByFarmId(farmId);
    }

    @GetMapping("comments/item/{itemid}")
    @ResponseBody
    public CommonResponse<List<ItemComment>> selectItemCommentsByFarmId(@PathVariable("itemid") int itemId) {
        return commentService.selectItemCommentsByFarmId(itemId);
    }

    @PostMapping("farmcomment")
    @ResponseBody
    public CommonResponse<String> addFarmComments(@RequestBody FarmComment farmComment,HttpServletRequest request) {
        return commentService.addFarmComments(farmComment,request);
    }

    @PostMapping("itemcomment")
    @ResponseBody
    public CommonResponse<String> addItemComments(@RequestBody ItemComment itemComment,HttpServletRequest request) {
        return commentService.addItemComments(itemComment,request);
    }

    @PutMapping("farmcomment")
    @ResponseBody
    public CommonResponse<String> updateFarmComments(@RequestBody FarmComment farmComment,HttpServletRequest request) {
        return commentService.updateFarmComments(farmComment,request);
    }

    @PutMapping("itemcomment")
    @ResponseBody
    public CommonResponse<String> updateItemComments(@RequestBody ItemComment itemComment,HttpServletRequest request) {
        return commentService.updateItemComments(itemComment,request);
    }
}
